function pailiang(selectid, statename, hidden_input_name) {
    $.get("car/get_pailiang", {farther_id: pinpai_id},
            function (req) {
//                var opttt = "";
//                for (var i = 0; i < req.length; i++)
//                {
//                    opttt = opttt + '<option value="' + req[i].id + '">' + req[i].valueInput + '</option>';
//
//                }
                var opttt = "<table class='table table-striped'>";
                for (var i = 0; i < req.length; i++)
                {
                    opttt = opttt + '<tr><td class=pailiang_item id="' + req[i].id + '">' + req[i].valueInput
                            + '</td> <td style="font-size:9px">'
                            //+ '(<a href="javascript:cartype_update(\'cartypebox\',' + req[i].id + ')">Edit</a> | '
                            + '(<a href="javascript:pailiang_del(' + req[i].id + ')">Del</a>)</td></tr>';
                }
                opttt = opttt + "</table>";

                $(selectid).html(opttt);

                var sso = $("#pailiang_select .pailiang_item");
                sso.click(function () {
                    //alert($(this).val()+$(this).html());
                    pinpai_id = $(this).attr('id');
                    $(hidden_input_name).val(pinpai_id);
                    $(statename).html("已选择 " + $(this).attr('id') + "--" + $(this).html());
                    pailiang_name = $(this).html();
                });

            }
    );
}


//var country_name = "";
//var pinpai_name = "";
//var xilie_name = "";
//var pailiang_name = "";
//var nianfen_name = "";

function getbaojia() {
    $.get("car/get_baojia", {country_name: country_name, pinpai_name: pinpai_name,
        xilie_name: xilie_name, pailiang_name: pailiang_name, nianfen_name: nianfen_name},
            function (req) {
                var opttt = "";
                for (var i = 0; i < req.length; i++)
                {
                    opttt = opttt + '<span>' + req[i].baojia + '--<a href=' + req[i].url + '>链接</a>' + ' <a href=car/del_baojia?id=' + req[i].id + '>(删除)</a></span>';

                }
                $("#baojia_select").html(opttt);
                if (req.length == 0) {
                    //alert("no result");


                    $("#baojia_btn").click();
                }

            }
    );
}

function country_del(id) {
    if (confirm("是否删除")) {
        $.get("car/country_del", {country_id: id, },
                function (req) {
                    location.reload();
                }
        );
    } else {
        return false;
    }
}function feedback_del(id) {
    if (confirm("是否删除")) {
        $.get("feedback/del", {country_id: id, },
                function (req) {
                    location.reload();
                }
        );
    } else {
        return false;
    }
}
function pinpai_del(id) {
    if (confirm("是否删除")) {
        $.get("car/pinpai_del", {id: id, },
                function (req) {
//                    location.reload();
                    showpinpai("#pinpai_select", "#pinpaistate", "#cartype_id_input");
                }
        );
    } else {
        return false;
    }

}
function cartype_del(id) {
    if (confirm("是否删除")) {
        $.get("car/cartype_del", {id: id, },
                function (req) {
                    location.reload();
                }
        );
    } else {
        return false;
    }
}
function pailiang_del(id) {
    if (confirm("是否删除")) {
        $.get("car/pailiang_del", {id: id, },
                function (req) {
//                    location.reload();
                    var vname = "pailiang";
                    pailiang("#" + vname + "_select", "#" + vname + "state", "#" + vname + "_id_input");
                }
        );
    } else {
        return false;
    }
}
var country_edit_id;
function country_update(id, c_id) {
    country_edit_id = c_id;
    pumpbox(id);
    $("#countryname_id").val("");
}


var pinpai_edit_id;
function pinpai_update(id, c_id) {
    pinpai_edit_id = c_id;
    pumpbox(id);
    $("#pinpaibox_name").val("");
}
function pumpbox(id) {
    var modalLocation = $(this).attr('data-reveal-id');
    var obj = new Object();
    obj.animation = "fade";
    obj.revealId = id;
    $("#" + id).reveal(obj);
}

function country_edit() {
    $.get("car/country_edit", {country_id: country_edit_id, countryname: $("#countryname_id").val()},
            function (req) {
                location.reload();
            }
    );
}
function pinpai_edit() {
    $.get("car/pinpai_edit", {id: pinpai_edit_id, countryname: $("#pinpaibox_name").val()},
            function (req) {
//                location.reload();
                showpinpai("#pinpai_select", "#pinpaistate", "#cartype_id_input");
                modelnow.trigger('reveal:close'); //关闭当前box
            }
    );
}

var cartype_edit_id;
function cartype_update(id, c_id) {
    cartype_edit_id = c_id;
    pumpbox(id);
    $("#cartypename").val("");
    $("#baojia_URL_input_box").val("");
}

function cartype_edit() {
    $.get("car/cartype_edit", {id: cartype_edit_id, cartype: $("#cartypename").val(),
        baojia_URL_input: $("#baojia_URL_input_box").val()},
            function (req) {
//                location.reload();
                cartype("#cartype_select", "#cartypestate", "#pailiang_id_input");
                modelnow.trigger('reveal:close'); //关闭当前box
            }
    );
}
